const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const baseConfig = require("./webpack.base")();

const NPMPackage = require("../package.json");

const { name: packageName } = NPMPackage;

module.exports = () => {
  const dev = process.env.NODE_ENV !== "production";
  const webpackConfig = {
    entry: {
      strap: [path.resolve(__dirname, "../src/index")],
    },
    output: {
      pathinfo: false,
      // path: PACK_PATH,
      filename: "[name].js",
      library: `${packageName}_[name]`,
      libraryTarget: "umd",
      jsonpFunction: `webpackJsonp_${packageName}`,
    },
    plugins: [
      new HtmlWebpackPlugin({
        title: "BitGame",
        template: "./public/index.ejs",
        filename: "index.html",
        inject: true,
      }),
      dev ? new webpack.HotModuleReplacementPlugin() : null,
    ].filter(Boolean),
  };

  return require("webpack-merge")(baseConfig, webpackConfig);
};
